<?php

define('PERM_ALL', true);

/**
 * @type : defines
 **/
function hasPerm( $perm, $type=PERM_ALL ) {
  if(!isset($_SESSION['uid'])) {
    // login mock user, guest
    require_once('../util/user.php');
    loginDrone('guest');
  }

  $nodes = explode('.', $perm);
  $ptrpos = &$_SESSION['user']['ptree']['root'];

  foreach( $nodes as $node ) {
    // XXX to avoid a scalar as array warning
    @$ptrpos = &$ptrpos[$node];
    if( $ptrpos === null ) 
      return false;
    if( !is_array($ptrpos) && $ptrpos === $type )
      return true;
  }

  if( !is_array($ptrpos) && $ptrpos === $type )
    return true; // doesn't check for type, however
  return false;
}

?>
